//#define _LARGEFILE64_SOURCE
//#define _FILE_OFFSET_BITS 64
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
int main(int argc,char *argv[])
{
    int file1, file2, filer, filew;
    long i;
    off_t off;
    void *buf;
    off_t len;
    struct stat size;
    len=atoll(argv[2]);//将argv[2]转为整型
    //a=len; //相当于二位数组 获取main的第二个参数
    
    buf=malloc(len);
    printf("the size is:  %d\n",len);
    sleep(3);
 if(argc<=3)
 {
     printf("this is the 1st one\n");
    if((file2=open(argv[1],O_RDWR|O_CREAT|O_APPEND,00644))==-1)//O_APPEND 原子操作
        printf("open file2 failed\n");
    else
        printf("created target file\n");

    if((filew=write(file2,buf,len))==-1)
        perror("failed to write");
    printf("the offset1 is %lld\n",off); //打印off_set
    printf("\n\nAll Done!\n\n");
 }
 else if(argc>=4)
 {
     printf("this is th 2nd one\n");
     if((file1=open(argv[1],O_RDWR|O_CREAT,00644))==-1)
         printf("open target file failed\n");
     else
         printf("ok\n");
            lseek(file1,0,SEEK_END);
            
    if((filew=write(file1,buf,len))==-1)
                {
                    perror("write data failed");
                }

    printf("the offset2 is %lld\n",off);
     printf("All Done\n");
 }
}
